﻿using System;
using System.Collections.Generic;
using System.Text;

namespace EmbeddedSharp.Core.Function.Maths {

    /// <summary>
    /// Log
    /// </summary>
    [Function("ln", "Gives the logarithm of e", "a=ln(10);", "a==6.90776")]
    public class LnNode : FuncNode {
        public LnNode()
            : base("ln") {
        }

        public override FuncNode GetReversedFunction(int index) {
            return new PowerENode();
        }

        public override object Evaluate() {
            if (Parameters.Count == 0) {
                throw new ArgumentException("usage: ln(value)");
            }

            double ret = Convert.ToDouble(Parameters[0].Evaluate());
            return System.Math.Pow(ret, 1 / 2.71828).ToString();
        }
    }
}
